'''
Settings file:
    the *import_* func import a package
    with the given *name* and *only* returns
    the package on the last level

    configs :

    - get_model :   a func that recieves the prefix 
                    of item ( defines below ) and return
                    the mapper to tell the model and actions

    - model_file_format : the format that should import

    - import_model : the func that imports model (class instead of package)

    the controllers does the similar work
                    
'''
import string

def import_(name):

    package=__import__(name)

    while '.' in name :
        second=name.split('.',2)[1]
        package=getattr(package,second)
        name=name.split('.',1)[1]

    return package

def urlopen(data,url):
    import urllib2

    try :
        return urllib2.urlopen(data)
    except :
        return urllib2.urlopen(url)
#models here
import model.routings

get_model = model.routings.get_model # it default recive a type as argument

model_file_format = 'model.%s'

model_format = lambda name : '%sModel' % string.capitalize(name)

import_model = lambda name : getattr(import_(model_file_format % name),model_format(name))

model_prefix = lambda item : type(item)

#controllers here
import routings

get_mapper = routings.get_mapper

controller_file_format = 'controller.%s'

controller_format = lambda name : '%sController' % string.capitalize(name)

import_controller = lambda name : \
        getattr(import_(controller_file_format % name),controller_format(name))

url_prefix = lambda url : url.domain

url_using = lambda url : url.path
start_urls=['',]
